package geos

import (
	"github.com/paulmach/orb/encoding/wkt"
	"github.com/paulmach/orb/planar"
	"strings"
)

// 判断点是否在多边形里面
func PolygonContainPoint(polygonStr string, pointStr string) (bool, error) {
	pointStr = strings.ReplaceAll(pointStr, "SRID=4326;", "")
	polygonStr = strings.ReplaceAll(polygonStr, "SRID=4326;", "")

	polyone, err := wkt.UnmarshalPolygon(polygonStr)
	if err != nil {
		return false, err
	}
	point, err := wkt.UnmarshalPoint(pointStr)
	if err != nil {
		return false, err
	}
	contains := planar.PolygonContains(polyone, point)
	return contains, nil
}
